package com.design.yjx.command.remote;

import com.design.yjx.command.common.Command;
import com.design.yjx.command.common.NoCommand;

/**
 * @author yuanjianxin
 * @date 2017/8/21 14:59
 */
public class RemoteControl {

    private Command[] onCommand;
    private Command[] offCommand;
    private Command undoCommand;

    public RemoteControl() {
        onCommand = new Command[7];
        offCommand = new Command[7];

        NoCommand noCommand = new NoCommand();
        for (int i = 0; i < 7; i++) {
            onCommand[i] = noCommand;
            offCommand[i] = noCommand;
        }
        undoCommand = noCommand;
    }


    public void setCommand(int slot, Command onCommand, Command offCommand) {
        this.onCommand[slot] = onCommand;
        this.offCommand[slot] = offCommand;
    }

    public void onButtonWasPushed(int slot) {
        onCommand[slot].execute();
        undoCommand = onCommand[slot];
    }

    public void offButtonWasPushed(int slot) {
        offCommand[slot].execute();
        undoCommand = offCommand[slot];
    }

    public void undoButtonWasPushed() {
        undoCommand.undo();
    }


}
